package com.example.controller;

import com.example.dao.impl.UserDaoImpl;
import com.example.pojo.User;
import com.example.service.UserService;
import com.example.service.impl.UserServiceImpl;
import com.example.utils.ResultUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {
    @Resource(name = "userService")
    public UserService userService;

    @RequestMapping("/login")
    @ResponseBody
    public User login(HttpSession session, String username, String password) throws Exception {
        return userService.login(username,password);
    }


    @RequestMapping("/user/topiclist")
    @ResponseBody
    public List<Map<String,Object>> getUserTopicList(Integer uId) {
        return userService.getUserTopicList(uId);
    }

    @RequestMapping("/user/collectionlist")
    @ResponseBody
    public List<Map<String,Object>> getUserCollectionList(Integer uId) {
        return userService.getUserCollectionList(uId);
    }

    @RequestMapping("/user/newslist")
    @ResponseBody
    public List<Map<String,Object>> getUserNewsList(Integer uId) {
        return userService.getUserNewsList(uId);
    }

    @RequestMapping("/user/updatepass")
    @ResponseBody
    public Integer updatePass (Integer uId,String password) {
        return userService.updatePass(uId,password);
    }

    @RequestMapping("/user/topic")
    @ResponseBody
    public Map<String,Object> getTopic(Integer tId) {
        return userService.getTopic(tId);
    }

    @RequestMapping("/otheruser")
    @ResponseBody
    public Map<String,Object> getOtherUser(Integer uId) {
        return userService.getOtherUser(uId);
    }

    @RequestMapping("/upload/uploadavatar")
    @ResponseBody
    public String updatePass (Integer uId, MultipartFile file,HttpServletRequest request) {
        return userService.uploadAvatar(file,uId,request);
    }

    @RequestMapping("/user/updateinfo")
    @ResponseBody
    public Integer updatePass (Integer uId, String nickname,String phone,String email) {
        return userService.updateInfo(uId,nickname,phone,email);
    }
}
